﻿Public Class clsXjPgd
    Public Function getXjPgd(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT a.sys_id,a.factory_id,a.xj_pgd_code,a.mes_project_name,a.oper_date,a.support_model,"
        szSql &= "a.bz,a.validity,a.status,a.operator,a.oper_count,a.note,a.finish_count,a.b_pgd_mes_sys_id,a.update_time,a.jp_type,a.jp_layer_num,"
        szSql &= "b.name,c.mes_project_code,c.mes_project_name,d.jp_size,d.jp_size_bore,d.jp_st_wt FROM sf.b_pgd_xj_details a "
        szSql &= " left join sf.t_mst_bz b on a.bz = b.sys_id "
        szSql &= " left join sf.b_pgd_mes c on a.b_pgd_mes_sys_id = c.sys_id "
        szSql &= " left join sf.t_prod_spec d on a.support_model = d.prod_spec_id "
        szSql &= " WHERE 1 = 1 "
        szSql &= " and a.factory_id = ? "
        If startTime <> "" Then
            szSql &= " and a.oper_date >= ? "
        End If
        If endTime <> "" Then
            szSql &= " and a.oper_date <= ? "
        End If
        szSql &= " and a.validity = ? "
        szSql &= " ORDER BY oper_date ASC"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", startTime, endTime, "1")
        If IsNothing(dt) Then
            getXjPgd = New DataTable
        Else
            getXjPgd = dt
        End If
    End Function

    Public Function updateFinishCount(finish_count As String, id As String, mes_id As String) As Integer
        Dim sql As String = String.Empty
        Dim rtn As Integer = 0
        DBacs.BeginTransaction()
        Try
            sql = String.Empty
            sql &= "UPDATE sf.b_pgd_xj_details SET finish_count = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= " WHERE sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1, finish_count, id)
            sql = String.Empty
            sql &= "UPDATE sf.b_pgd_mes SET finish_count = ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            sql &= " WHERE sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1, finish_count, mes_id)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
        End Try
        Return rtn
    End Function

End Class
